package com.zr.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.model.LMuser;
import com.zr.service.FuncService;
import com.zr.util.PrintWriterUtil;
/**
 * 不同的用户进入能够展现不同的功能
 * @author Administrator
 *
 */
@Controller
@Scope(value="prototype")
public class ShowFunAction extends ActionSupport implements SessionAware,ServletResponseAware{
	@Resource
	private FuncService funcservice;

	private Map<String, Object> session;
	private HttpServletResponse response;

	@Override
	public void setSession(Map<String, Object> arg0) {
		// TODO Auto-generated method stub
		this.session = arg0;
	}

	@Override
	public void setServletResponse(HttpServletResponse arg0) {
		// TODO Auto-generated method stub
		this.response = arg0;
	}

	public String showFuncs(){
//		禁止本地缓存，为了让用户注销后不再进入main界面——但是浏览器能自动提交上一次的数据
		 response.setHeader("Pragma","No-cache"); 
		 response.setHeader("Cache-Control","No-cache"); 
		 response.setDateHeader("Expires", -1); 
		 response.setHeader("Cache-Control", "No-store");

		LMuser u = (LMuser) session.get("user");
		if(u != null){
			int rid = u.getLMrole().getRid();
			PrintWriterUtil.getPW(response).write(funcservice.getCurrentFuncsByPartentId(-1, rid).toString());
			PrintWriterUtil.closePW(response);
			return null;
		}else{
			return ERROR;
		}
	}
}
